package diamonds;

import javax.faces.event.ActionEvent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.backbase.bjs.event.CustomActionEvent;
import com.backbase.bjs.component.UIBackbaseApplication;
import com.backbase.bjs.component.UIBackbaseCommandButton;
import com.backbase.bjs.component.UIBackbaseOutputText;
import com.backbase.bjs.component.bxml.UIBackbasePanelSet;
import com.backbase.bjs.component.bxml.UIBackbaseWindow;
import com.backbase.bjs.component.bxml.UIBackbaseModal;

public class ControllerBean {
  private static final Log log = LogFactory.getLog(ControllerBean.class);

  private UIBackbaseApplication application;
  private UIBackbaseModal loginDialog;
  private UIBackbaseOutputText loginStatus;
  private UIBackbasePanelSet topPanelSet;
  private UIBackbaseOutputText statusText;

  private UserBean user;
  
  private UIBackbaseCommandButton button1;

	private UIBackbaseOutputText calcoutput;

	public UIBackbaseWindow DHome;

	private String button1Title = "Backbase commandButton";

	public void openDHome(ActionEvent event) {
		log.info("open Diamonds home window");
		DHome.setShow(true);
	}

	public UIBackbaseWindow getDHome() {
		return DHome;
	}

	public void setDHome(UIBackbaseWindow window) {
		this.DHome = window;
	}

	UIBackbaseWindow consort;

	public void openConsort(ActionEvent event) {
		log.info("open Consortium window");
		consort.setShow(true);
	}

	public UIBackbaseWindow getConsort() {
		return consort;
	}

	public void setConsort(UIBackbaseWindow window) {
		this.consort = window;
	}

	UIBackbaseWindow window;

	public void openWindow(ActionEvent event) {
		log.info("A server side actionEvent, open window");
		window.setShow(true);
	}

	public UIBackbaseWindow getWindow() {
		return window;
	}

	public void setWindow(UIBackbaseWindow window) {
		this.window = window;
	}

	UIBackbaseModal modalExp;

	public void openModalExp(ActionEvent event) {
		log.info("A server side actionEvent, open modal");
		modalExp.setShow(true);
	}

	public UIBackbaseModal getModalExp() {
		return modalExp;
	}

	public void setModalExp(UIBackbaseModal modal) {
		this.modalExp = modal;
	}

	public UIBackbaseCommandButton getButton1() {
		return button1;
	}

  public void closeModalExp(ActionEvent event) {
  	log.info("closeModalExp() called");
  	modalExp.setShow(false);
  }
	
	public String getButton1Title() {
		return button1Title;
	}

	public void setButton1(UIBackbaseCommandButton button1) {
		this.button1 = button1;
	}

	public void printAttribute(CustomActionEvent event) {
		System.out.print("First name is: " + event.getAtts().get("firstname"));
	}

	private UIBackbaseCommandButton button2;

	private boolean button2Rendered;

	public UIBackbaseCommandButton getButton2() {
		return button2;
	}

	public void setButton2(UIBackbaseCommandButton button2) {
		this.button2 = button2;
	}

	public void addTwoNumbers() {
		calcoutput.setValue(44 + 33);
	}

	public String someBusinessLogic2() {
		log.info("A second server side action!!!!");
		return null;
	}

	public void doTwo(ActionEvent event) {
		button2Rendered = false;
	}

	public boolean isButton2Rendered() {
		return button2Rendered;
	}

	public void setButton2Rendered(boolean button2Rendered) {
		this.button2Rendered = button2Rendered;
	}

	public UIBackbaseOutputText getCalcoutput() {
		return calcoutput;
	}

	public void setCalcoutput(UIBackbaseOutputText calcoutput) {
		this.calcoutput = calcoutput;
	}

	public UIBackbaseModal getLoginDialog() {
		return loginDialog;
	}

	public void setLoginDialog(UIBackbaseModal loginModal) {
		this.loginDialog = loginModal;
	}
	
	public void loginDialogAction(ActionEvent event) {
		log.info("A server side actionEvent");
		log.info(user.getSessionId() + ":" + user.getAuthError());
		if ( !(user.getSessionId() != null && user.getAuthError() == null ))
			loginDialog.setShow(true);
	}

	public UIBackbaseOutputText getLoginStatus() {
		return loginStatus;
	}

	public void setLoginStatus(UIBackbaseOutputText loginStatus) {
		this.loginStatus = loginStatus;
	}

	public UIBackbaseApplication getApplication() {
		return application;
	}

	public void setApplication(UIBackbaseApplication application) {
		this.application = application;
	}

	public UserBean getUser() {
		return user;
	}

	public void setUser(UserBean user) {
		this.user = user;
	}

	public UIBackbasePanelSet getTopPanelSet() {
		return topPanelSet;
	}

	public void setTopPanelSet(UIBackbasePanelSet topPanelSet) {
		this.topPanelSet = topPanelSet;
	}

	public UIBackbaseOutputText getStatusText() {
		return statusText;
	}

	public void setStatusText(UIBackbaseOutputText statusText) {
		this.statusText = statusText;
	}
}